package com.springboot.project.mockData;

import com.springboot.project.entity.ExcelTableTitle;

import java.util.ArrayList;
import java.util.List;

public class ExcelTableTitleMock {
    static List<ExcelTableTitle> list = new ArrayList<>();

    public static List<ExcelTableTitle> getExcelTableTitle() {
        ExcelTableTitle tableTitle;
        tableTitle = new ExcelTableTitle(1, "单位名称", 0);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(2, "发电量", 0);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(3, "计划发电出力", 0);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(4, "实际发电出力", 0);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(5, "月计划", 2);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(6, "日计划", 2);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(7, "日实际", 2);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(8, "月累计", 2);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(9, "高峰", 3);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(10, "低谷", 3);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(11, "高峰", 4);
        list.add(tableTitle);
        tableTitle = new ExcelTableTitle(12, "低谷", 4);
        list.add(tableTitle);
        return build(list);
    }

    public static List<ExcelTableTitle> build(List<ExcelTableTitle> list){
        List<ExcelTableTitle> tableTitles = new ArrayList<>();

        for(ExcelTableTitle tableTitle : list){
           if(tableTitle.getParentId() == 0) {
               tableTitles.add(tableTitle);
               buildChild(list,tableTitle);
           }
        }
        return tableTitles;
    }

    public static void buildChild(List<ExcelTableTitle> list,ExcelTableTitle tableTitle){
        tableTitle.setList(new ArrayList<>());
        for(ExcelTableTitle child : list){
            if(child.getParentId().equals(tableTitle.getId()) ){
                tableTitle.getList().add(child);
            }
        }
    }


}
